
#ifndef __LIBERTY_LIBRARY_LOCALMUTEX_H__
#define __LIBERTY_LIBRARY_LOCALMUTEX_H__

#include <Liberty3D/Liberty3D.h>
#include <Liberty3D/Library/IMutex.h>

#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>

namespace Liberty { namespace Library { namespace Mutex { namespace Impl { namespace Local {
    class Mutex : public IMutex {
    protected:
        mutable boost::mutex _mutex;

    public:
        Mutex();

    public:
        virtual IExclusiveLock* lock();
    };

    class SharedMutex : public ISharedMutex {
    protected:
        mutable boost::shared_mutex _mutex;

    public:
        SharedMutex();

    public:
        virtual IExclusiveLock* lock();
        virtual ISharedLock*    lockShared();
    };

    class SharedLock : public ISharedLock {
    public:
        boost::upgrade_lock<boost::shared_mutex> _guard;

    public:
        SharedLock(boost::shared_mutex& mutex);

    public:
        virtual IExclusiveLock* upgrade();
    };

    class Lock : public IExclusiveLock {
    public:
        boost::lock_guard<boost::mutex> _guard;

    public:
        Lock(boost::mutex& mutex);
    };

    class UpgradedLock : public IExclusiveLock {
    public:
        boost::upgrade_to_unique_lock<boost::shared_mutex> _guard;

    public:
        UpgradedLock(boost::upgrade_lock<boost::shared_mutex>& guard);
    };

    class UniqueLock : public IExclusiveLock {
    public:
        boost::unique_lock<boost::shared_mutex> _guard;

    public:
        UniqueLock(boost::shared_mutex& mutex);
    };
}}}}}

#endif
